namespace Microsoft.Robotics.Manipulation.Visualization
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;

    /// <summary>
    /// Interaction logic for ArmPositionDisplayView.xaml
    /// </summary>
    public partial class ArmPositionDisplayView : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the ArmPositionDisplayView class
        /// </summary>
        public ArmPositionDisplayView()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Handler for handling the joint manual entry update button
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void JointUpdate_Click(object sender, RoutedEventArgs e)
        {
            this.JointUpdateCheckBox.IsChecked = true;
        }

        /// <summary>
        /// Handler for handling the Cartesian Position manual entry sync button
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void CartesianSync_Click(object sender, RoutedEventArgs e)
        {
            this.CartesianPositionManual.Text = this.CartesianPositionLabel.Content.ToString().Replace(',', ' ');
            this.CartesianOrientationManual.Text = this.CartesianOrientationLabel.Content.ToString().Replace(',', ' ');

            BindingOperations.GetBindingExpressionBase(this.CartesianPositionManual, TextBox.TextProperty).UpdateSource();
            BindingOperations.GetBindingExpressionBase(this.CartesianOrientationManual, TextBox.TextProperty).UpdateSource();
        }

        /// <summary>
        /// Handler for handling the Cartesian Position entry update button
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void CartesianManualUpdate_Click(object sender, RoutedEventArgs e)
        {
            this.CartesianManualUpdateCheckBox.IsChecked = true;
        }

        /// <summary>
        /// Handler for handling the Joint manual entry sync button
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void JointSync_Click(object sender, RoutedEventArgs e)
        {
            this.JointManualEntry.Text = this.CurrentJointPosition.Text;
        }

        /// <summary>
        /// Handles add position button click.
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void AddUpdatePosition_Click(object sender, RoutedEventArgs e)
        {
            this.UpdateCartesianPositionCheckBox.IsChecked = true;
        }

        /// <summary>
        /// Handles go to position button click.
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void GoToPosition_Click(object sender, RoutedEventArgs e)
        {
            this.GoToPositionCheckBox.IsChecked = true; 
        }

        /// <summary>
        /// Handles list box selection change
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void ListBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            e.Handled = true;
        }

        /// <summary>
        /// Handles save button clicks
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void SavePositions_Click(object sender, RoutedEventArgs e)
        {
            this.SavePositionsCheckBox.IsChecked = true;
        }

        /// <summary>
        /// Handles load button clicks
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void LoadPositions_Click(object sender, RoutedEventArgs e)
        {
            this.LoadPositionsCheckBox.IsChecked = true;
        }

        /// <summary>
        /// Handles touch button clicks
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void TouchPosition_Click(object sender, RoutedEventArgs e)
        {
            this.TouchCartesianPositionCheckBox.IsChecked = true;
        }

        /// <summary>
        /// Handles push button clicks
        /// </summary>
        /// <param name="sender">Element sender ignored</param>
        /// <param name="e">Action parameters ignored</param>
        private void PushPosition_Click(object sender, RoutedEventArgs e)
        {
            this.PushCartesianCheckBox.IsChecked = true;
        }
    }
}
